﻿using UnityEngine;
using System.Collections;
using System.Threading;

public class AniEffectGroup : AniEffectComplete {

	public AniEffectC[] aniEffectCs;

	private int aniEffectIndex;
	
	public override void play (OReportDetail detail, CallBack complete) {
		base.play(detail, complete);
		playGroup();
	}

	protected void playGroup() {
		if(aniEffectCs != null) {
			while(aniEffectIndex < aniEffectCs.Length) {
				AniEffectC aniEffectC = aniEffectCs[aniEffectIndex];
				++aniEffectIndex;
				if(!(aniEffectC == null || aniEffectC == this) && playGroup(aniEffectC)) {
					aniEffectC.gameObject.SetActive(true);
					aniEffectC.play(detail, playGroup);
					return;
				}
			}
		}

		playComplete();
	}

	protected virtual bool playGroup(AniEffectC aniEffectC) {
		return true;
	}
}
